package com.niannian.dialog;

import com.niannian.R;
import android.content.Context;
import android.sax.ElementListener;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class GenderDialog extends BaseDialog implements android.view.View.OnClickListener {

	private RelativeLayout ll_man;
	private RelativeLayout ll_woman;
	private onSimpleOnManListener mOnManListener;
	private onSimpleOnWomanListener mOnWomanListener;
	ImageView iv_man, iv_woman;
	String currentData = "";

	public GenderDialog(Context context, String currentData) {
		super(context);
		this.currentData = currentData;
		init();
	}

	private void init() {
		setContentView(R.layout.dialog_gender);

		ll_man = (RelativeLayout) findViewById(R.id.ll_man);
		ll_woman = (RelativeLayout) findViewById(R.id.ll_woman);
		ll_man.setOnClickListener(this);
		ll_woman.setOnClickListener(this);

		iv_man = (ImageView) findViewById(R.id.iv_man);
		iv_woman = (ImageView) findViewById(R.id.iv_woman);
		if ("M".equals(currentData)) {
			iv_man.setVisibility(View.VISIBLE);
			iv_woman.setVisibility(View.INVISIBLE);
		} else if ("F".equals(currentData)) {
			iv_man.setVisibility(View.INVISIBLE);
			iv_woman.setVisibility(View.VISIBLE);
		} else {
			iv_man.setVisibility(View.INVISIBLE);
			iv_woman.setVisibility(View.INVISIBLE);
		}
	}

	public void setOnManListener(onSimpleOnManListener listener) {
		mOnManListener = listener;
	}

	public void setOnWoManlListener(onSimpleOnWomanListener listener) {
		mOnWomanListener = listener;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.ll_man:
			iv_man.setVisibility(View.VISIBLE);
			iv_woman.setVisibility(View.INVISIBLE);
			mOnManListener.onMan();
			dismiss();
			break;
		case R.id.ll_woman:
			iv_man.setVisibility(View.INVISIBLE);
			iv_woman.setVisibility(View.VISIBLE);
			mOnWomanListener.onWoman();
			dismiss();
			break;
		default:
			break;
		}
	}

	@Override
	public void dismiss() {
		if (isShowing()) {
			super.dismiss();
		}
	}

	public interface onSimpleOnManListener {
		public void onMan();
	}

	public interface onSimpleOnWomanListener {
		public void onWoman();
	}

}
